GtkLabel: fix mnemonic-keyval when use-markup is true
authorSébastien Wilmet <swilmet@src.gnome.org>
Tue, 24 Apr 2012 20:22:22 +0000 (22:22 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 17 Mar 2013 20:10:10 +0000 (16:10 -0400)
To extract the mnemonic key value, the string must contain the
underscore. But when the "gtk-auto-mnemonics" setting is true and when
the Alt key is not pressed, the underscore must not be displayed. The
problem was that the 'new_str' variable was used for both purposes:
extract the text to display, and extract the accelerator character.

When the underscore must not be visible, the underscores were removed
from the 'new_str' variable before extracting the accelerator character.

Now there are two strings, one for each purpose.

https://bugzilla.gnome.org/show_bug.cgi?id=674759

gtk/gtklabel.c

index 8d18cf0c8acd34621a29b0256a77b7b50b6873d8..587a61f9ce32373d152ef55f9af0def2f35f5908 100644 (file)
@@ -2517,10 +2517,11 @@ gtk_label_set_markup_internal (GtkLabel    *label,
   GError *error = NULL;
   PangoAttrList *attrs = NULL;
   gunichar accel_char = 0;
-  gchar *new_str;
+  gchar *str_for_display = NULL;
+  gchar *str_for_accel = NULL;
   GList *links = NULL;
 
-  if (!parse_uri_markup (label, str, &new_str, &links, &error))
+  if (!parse_uri_markup (label, str, &str_for_display, &links, &error))
     {
       g_warning ("Failed to set text from markup due to error parsing markup: %s",
                  error->message);
@@ -2528,6 +2529,8 @@ gtk_label_set_markup_internal (GtkLabel    *label,
       return;
     }
 
+  str_for_accel = g_strdup (str_for_display);
+
   if (links)
     {
       gtk_label_ensure_select_info (label);
@@ -2555,31 +2558,51 @@ gtk_label_set_markup_internal (GtkLabel    *label,
           gchar *pattern;
           guint key;
 
-          if (separate_uline_pattern (new_str, &key, &tmp, &pattern))
+          if (separate_uline_pattern (str_for_display, &key, &tmp, &pattern))
             {
-              g_free (new_str);
-              new_str = tmp;
+              g_free (str_for_display);
+              str_for_display = tmp;
               g_free (pattern);
             }
         }
     }
 
-  if (!pango_parse_markup (new_str,
+  /* Extract the text to display */
+  if (!pango_parse_markup (str_for_display,
                            -1,
-                           with_uline ? '_' : 0,
+                           0,
                            &attrs,
                            &text,
-                           with_uline ? &accel_char : NULL,
+                           NULL,
                            &error))
     {
       g_warning ("Failed to set text from markup due to error parsing markup: %s",
                  error->message);
-      g_free (new_str);
+      g_free (str_for_display);
+      g_free (str_for_accel);
+      g_error_free (error);
+      return;
+    }
+
+  /* Extract the accelerator character */
+  if (with_uline && !pango_parse_markup (str_for_accel,
+                                        -1,
+                                        '_',
+                                        NULL,
+                                        NULL,
+                                        &accel_char,
+                                        &error))
+    {
+      g_warning ("Failed to set text from markup due to error parsing markup: %s",
+                 error->message);
+      g_free (str_for_display);
+      g_free (str_for_accel);
       g_error_free (error);
       return;
     }
 
-  g_free (new_str);
+  g_free (str_for_display);
+  g_free (str_for_accel);
 
   if (text)
     gtk_label_set_text_internal (label, text);